/*
 * File:   VerticalTableHandlerTest.cpp
 * Author: Guilherme Monteiro
 *
 */

#include "VerticalTableHandlerTest.h"

CPPUNIT_TEST_SUITE_REGISTRATION(VerticalTableHandlerTest);

VerticalTableHandlerTest::VerticalTableHandlerTest() {
}

VerticalTableHandlerTest::~VerticalTableHandlerTest() {
}

void VerticalTableHandlerTest::setUp() {
}

void VerticalTableHandlerTest::tearDown() {
}

void VerticalTableHandlerTest::testVerticalTableHandler1() {
    string lowImagePath = "";
    string highImagePath = "../books/caracterizacao/alta_resolucao/image278.png";
    
    try {
        VerticalTableHandler* verticalTableHandler = new VerticalTableHandler(lowImagePath, highImagePath);
    }
    catch(NullImageException &nie) {
        string msg = "ERROR ==> Image " + lowImagePath + " can't be loaded. Change the image path or the directory of execution";
        if (strcmp(nie.what(), msg.c_str()) != 0) {
            CPPUNIT_ASSERT(false);
        }
    }
}

void VerticalTableHandlerTest::testVerticalTableHandler2() {
    string lowImagePath = "../books/caracterizacao/alta_resolucao/image278.png";
    string highImagePath = "";
    
    try {
        VerticalTableHandler* verticalTableHandler = new VerticalTableHandler(lowImagePath, highImagePath);
    }
    catch(NullImageException &nie) {
        string msg = "ERROR ==> Image " + highImagePath + " can't be loaded. Change the image path or the directory of execution";
        if (strcmp(nie.what(), msg.c_str()) != 0) {
            CPPUNIT_ASSERT(false);
        }
    }
}

void VerticalTableHandlerTest::testVerticalTableHandler3() {
    string lowImagePath = "../books/caracterizacao/baixa_resolucao/image278.png";
    string highImagePath = "../books/caracterizacao/baixa_resolucao/image278.png";
    
    try {
        VerticalTableHandler* verticalTableHandler = new VerticalTableHandler(lowImagePath, highImagePath);
    }
    catch(NullImageException &nie) {
        string msg = "ERROR ==> Image " + highImagePath + " can't be loaded. Change the image path or the directory of execution";
        if (strcmp(nie.what(), msg.c_str()) != 0) {
            CPPUNIT_ASSERT(false);
        }
    }
}


void VerticalTableHandlerTest::testVerticalTableHandler4() {
    string lowImagePath = "../books/";
    string highImagePath = "../books/caracterizacao/baixa_resolucao/image278.png";
    
    try {
        VerticalTableHandler* verticalTableHandler = new VerticalTableHandler(lowImagePath, highImagePath);
    }
    catch(NullImageException &nie) {
        string msg = "ERROR ==> Image " + lowImagePath + " can't be loaded. Change the image path or the directory of execution";
        if (strcmp(nie.what(), msg.c_str()) != 0) {
            CPPUNIT_ASSERT(false);
        }
    }
}

void VerticalTableHandlerTest::testVerticalTableHandler5() {
    string lowImagePath = "../books/caracterizacao/baixa_resolucao/image278.png";
    string highImagePath = "../books/caracterizacao/";
    
    try {
        VerticalTableHandler* verticalTableHandler = new VerticalTableHandler(lowImagePath, highImagePath);
    }
    catch(NullImageException &nie) {
        string msg = "ERROR ==> Image " + highImagePath + " can't be loaded. Change the image path or the directory of execution";
        if (strcmp(nie.what(), msg.c_str()) != 0) {
            CPPUNIT_ASSERT(false);
        }
    }
}

void VerticalTableHandlerTest::testRotateImageInNinetyDegrees1() {
    string lowImagePath = "../books/caracterizacao/baixa_resolucao/image278.png";
    string highImagePath = "../books/caracterizacao/alta_resolucao/image278.png";
    
    try {
        VerticalTableHandler* verticalTableHandler = new VerticalTableHandler(lowImagePath, highImagePath);
        vector<string> result = verticalTableHandler->rotateImageInNinetyDegrees();
        
        string expectedNewRotatedLowImagePath = "../books/caracterizacao/baixa_resolucao/image278_r.png";
        string expectedNewRotatedHighImagePath = "../books/caracterizacao/alta_resolucao/image278_r.png";
        
        if(strcmp(result[0].c_str(), expectedNewRotatedLowImagePath.c_str()) != 0) {
            CPPUNIT_ASSERT(false);
        }
        
        if(strcmp(result[1].c_str(), expectedNewRotatedHighImagePath.c_str()) != 0) {
            CPPUNIT_ASSERT(false);
        }
    }
    catch(NullImageException &nie) {
        CPPUNIT_ASSERT(false);
    }
}

